<?php

namespace app\order\controller;

use app\common\controller\PCBase;
use app\common\library\Upload;
use app\order\logic\OrderDocumentLogic;
use app\order\model\Order as OrderModel;
use think\facade\Db;
use Throwable;

class OrderDocument extends PCBase
{
    /**
     * 模型
     * @var object
     * @phpstan-var OrderModel
     */
    protected object $model;

    public function initialize(): void
    {
        parent::initialize();
        $this->model = new OrderModel();
    }

    /**
     * 查看-列表
     * @throws Throwable
     */
    public function index()
    {
        $params     = $this->request->post();
        $orderLogic = new OrderDocumentLogic();
        return $orderLogic->getTkOrderList($params);
    }


    /**
     * 查看-列表
     * @throws Throwable
     */
    public function edit($id='')
    {
        $orderLogic = new OrderDocumentLogic();
        $row = $orderLogic->get_row($id);
        if (!$row) {
            return json(DefaultResponse(201, false, '记录不能为空!', null));
        }
        if ($this->request->isPost()) {
            $data = $this->request->post();


            return $orderLogic->editTkOrderList($row, $data);
        }

        return json(DefaultResponse(200, true, '获取成功', ['row' => $row]));
    }




    /**
     * @desc  批量创建面单
     * @date  2024/3/21
     * @return \think\response\Json
     * @author ligang
     */
    public function shippingDocuments()
    {
        $params = $this->request->post();
        return (new OrderDocumentLogic())->createShippingDocuments($params);
    }



    /**
     * @desc  获取批次列表
     * @date  2024/4/19
     * @return \think\response\Json
     * @author luckyXiong
     */
    public function getBactchList()
    {
        $params = $this->request->post();
        return (new OrderDocumentLogic())->getBatchList($params);
    }


    /**
     * @desc  获取批次列表详情
     * @date  2024/4/19
     * @return \think\response\Json
     * @author luckyXiong
     */
    public function getBatchLog()
    {
        $params = $this->request->post();
        return (new OrderDocumentLogic())->getBatchLog($params);
    }



    /**
     * @desc  获取批次列表详情导出
     * @date  2024/4/19
     * @return \think\response\Json
     * @author luckyXiong
     */
    public function exportLog()
    {
        $params = $this->request->post();
        return (new OrderDocumentLogic())->exportLog($params);
    }





    /**
     * @desc 订单-标记成已处理
     * @date  2024/3/21 0021
     * @return \think\response\Json
     * @author ligang
     */
    public function markerOrderDoc()
    {
        $params = $this->request->post();
        $orderShipLogic = new OrderDocumentLogic();
        return $orderShipLogic->markerOrderDocument($params);
    }

    /**
     * 订单导出
     */
    public function export()
    {
        $params     = $this->request->post();
        return (new OrderDocumentLogic())->exportOrder($params);
    }


    /**
     * @desc  创建
     * @param $order_id
     * @return mixed
     */
    public function getLogInfo($order_id)
    {
        $params         = $this->request->post();
        $orderShipLogic = new OrderDocumentLogic();
        return $orderShipLogic->getLogInfo($params);
    }
}
